Return to doc.sitecore.com

Valid for Sitecore 5.2, 5.1.1
  The database Element
Prev Next

The web.config <database> element defines a data store for Sitecore items. Only databases defined below the main <databases> element are considered valid. The bare minimum for a database definition is:

<database id="myDB" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
  <param desc="name">$(id)</param>
</database>

This will define a database called 'myDB' that can be accessed from within the Sitecore API in the following way:

 Database database = Factory.GetDatabase("myDB");
 
 MainUtil.Out("Got the database: " + database.Name);

This code will output the message:

 Got the database: myDB

Note that all threads in the process will share a single instance of the database object due to the attribute 'singleInstance' on the <database> element.  The database defined above will not contain any data as it has not yet been told where and how to retrieve its data.  We do this with data provider elements.


Prev Next